package com.yanqu.road.server.cmd.monopolymarket;

import com.yanqu.road.entity.enums.eMonopolyMarketResType;
import com.yanqu.road.pb.monopolymarket.MonopolyMarketProto;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.command.Command;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.manger.monopolymarket.MonopolyMarketMgr;
import com.yanqu.road.server.manger.player.GamePlayerMgr;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.GameProtocol;
import com.yanqu.road.utils.BitUtil;
import io.netty.channel.ChannelHandlerContext;

import java.util.List;

/**
 * @Description
 * @Author cwq
 * @Data 2021/8/11 16:32
 */
@Cmd(code = GameProtocol.S_MONOPOLY_MARKET_RESET_SYSTEM, desc = "通知区服活动结束重置数据 跨服返回区服 协议")
public class MonopolyMarketSynResetSystemCmd implements Command {

    @Override
    public void execute(ChannelHandlerContext ctx, YanQuMessage packet) throws Exception {
        MonopolyMarketProto.MonopolyMarketResetToGameServerMsg synMsg = MonopolyMarketProto.MonopolyMarketResetToGameServerMsg.parseFrom(packet.getBytes());
        int bit = synMsg.getBit();
        if(bit <= 0){
            return;
        }
        List<GamePlayer> playerLis = GamePlayerMgr.getAllOnlinePlayer();
        for (GamePlayer player : playerLis) {
            if (!MonopolyMarketMgr.canEnterSystem(player)) {
                continue;
            }
            // 目前只需要重置玩家数据 不需要派遣的大臣数据
            MonopolyMarketMgr.refreshUser(player,false,true);
            if(BitUtil.get(bit, eMonopolyMarketResType.FORTRESS.getValue() - 1)){
                // 如果在系统里面 去领取 要塞采集奖励
                MonopolyMarketMgr.attemptReceiveCollectReward(player);
            }
        }
        MonopolyMarketMgr.logger.info("收到榷场活动结束的标识 bit:{}",bit);
    }
}
